home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.lang.c++
- Path: lion.cs.latrobe.edu.au!boylesgj
- From: boylesgj@lion.cs.latrobe.edu.au (Gregary J Boyles)
- Subject: Linker error problem
- X-Nntp-Posting-Host: lion.cs.latrobe.edu.au
- Message-ID: <DonKM5.MAM@latcs1.lat.oz.au>
- Sender: news@latcs1.lat.oz.au (news)
- Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
- Date: Fri, 22 Mar 1996 05:01:17 GMT
-
- I am getting a linker error as follows. Undefined symbol
- Address::ThisPtrList in module address.cpp.
- I don't understand this non sense because it is defined
- as a static class member and its value is initialized.
- See $$$$ for definitions #### for causes of the error (if
- I comment out these lines then the error disappears.
-
- // address.h
- #include <iostream.h>
-
- #ifndef __ADDRESS_H
- #define __ADDRESS_H
- #define SIZE 100
-
- #include "defines.h"
-
- class Address
- {
- private : int Number;
- char *Street;
- char *City;
- int Zip;
- $$$$$$ static Address *ThisPtrList[SIZE];
- static unsigned int NumberInstances;
- static unsigned int InstanceNumber;
-
- public : // Constructors
- Address(int ANumber,const char *AStreet,const char *ACity,int Zip);
- Address();
- // Copy constructor
- Address(Address& AnAddress);
- // Deconstructor
- ~Address();
- // Operator overloads
- friend ostream& operator << (ostream& OutPutStream,Address& AnAddress);
- friend istream& operator >>(istream& InPutStream,Address& AnAddress);
- // Functions
- void Change(int ANumber,const char *AStreet,const char *ACity,int AZip);
- unsigned int Address::NumberOfInstances();
- void Address::DisplayAll();
- };
-
- #endif
-
-
-
- // address.cpp
-
- #include "address.h"
- #include <string.h>
- #include <iostream.h>
-
- // Data initializations
- unsigned int Address::NumberInstances=0;
-
- unsigned int Address::InstanceNumber=0;
-
- $$$$ Address Address::*ThisPtrList={0};
-
- // Constructors
- Address::Address(int ANumber,const char *AStreet,const char *ACity,int AZip)
- {
- Number=ANumber;
- Street=new char[strlen(AStreet)+1];
- strcpy(Street,AStreet);
- City=new char[strlen(ACity)+1];
- strcpy(City,ACity);
- Zip=AZip;
- #### ThisPtrList[NumberInstances]=this;
- NumberInstances++;
- InstanceNumber=NumberInstances;
- }
-
- Address::Address()
- {
- Number=0;
- Street=new char[strlen("")+1];
- strcpy(Street,"");
- City=new char[strlen("")+1];
- strcpy(City,"");
- Zip=0;
- #### ThisPtrList[NumberInstances]=this;
- NumberInstances++;
- InstanceNumber=NumberInstances;
- }
-
- // Copy constructor
- Address::Address(Address& AnAddress)
- {
- Number=AnAddress.Number;
- Street=new char[strlen(AnAddress.Street)+1];
- strcpy(Street,AnAddress.Street);
- City=new char[strlen(AnAddress.City)+1];
- strcpy(City,AnAddress.City);
- Zip=AnAddress.Zip;
- #### ThisPtrList[NumberInstances]=this;
- NumberInstances++;
- InstanceNumber=NumberInstances;
- }
-
- // Deconstructor
- Address::~Address()
- {
- Number=0;
- delete Street;
- delete City;
- Zip=0;
- }
-
- // Operator overloads
- ostream& operator <<(ostream& OutPutStream,Address& AnAddress)
- {
- OutPutStream<<"Street : "<<AnAddress.Number<<" "<<AnAddress.Street<<EOLN;
- OutPutStream<<"City : "<<AnAddress.City<<EOLN;
- OutPutStream<<"Zip code : "<<AnAddress.Zip<<EOLN;
- return(OutPutStream);
- }
-
-
- istream& operator >>(istream& InPutStream,Address& AnAddress)
- {
- char *StreetName,*CityName,ch;
-
- StreetName=new char[50];
- CityName=new char[50];
- cout<<"Number : ";
- cin>>AnAddress.Number;
- GetEndOfLine();
- cout<<"Street : ";
- cin.getline(StreetName,49,EOLN);
- delete AnAddress.Street;
- AnAddress.Street=new char[strlen(StreetName)+1];
- strcpy(AnAddress.Street,StreetName);
- cout<<"City : ";
- cin.getline(CityName,49,EOLN);
- delete AnAddress.City;
- AnAddress.City=new char[strlen(CityName)+1];
- strcpy(AnAddress.City,CityName);
- cout<<"City : ";
- cout<<"Zip code : ";
- cin>>AnAddress.Zip;
- GetEndOfLine();
- return(InPutStream);
- }
-
- // Functions
- void Address::Change(int ANumber,const char *AStreet,const char *ACity,int AZip)
- {
- Number=ANumber;
- delete Street;
- Street=new char[strlen(AStreet)+1];
- strcpy(Street,AStreet);
- delete City;
- City=new char[strlen(ACity)+1];
- strcpy(City,ACity);
- Zip=AZip;
- }
-
- unsigned int Address::NumberOfInstances()
- {
- return(NumberInstances);
- }
-
- void Address::DisplayAll()
- {
- unsigned int Index;
-
- cout<<EOLN;
- for (Index=0;Index<NumberInstances;Index++)
- {
- #### cout<<ThisPtrList[Index]<<EOLN;
- }
- }
-